Augustin Luna
26 January, 2016
Research Fellow
Department of Biostatistics and Computational Biology
Dana-Farber Cancer Institute
shiny R package
fluidPage: Expand components to fill pagetitlePanel: Adds page titlesidebarLayout: Sets page layoutsidebarPanel: Sidebar contentsmainPanel: Main page contents# ui.R
shinyUI(fluidPage(
titlePanel("Hello World!"),
sidebarLayout(
sidebarPanel("Side Bar"),
mainPanel("Main Panel")
)
))
# server.R
shinyServer(function(input, output) {
# NOTHING
})
runApp() in the folder with app filesrcellminer
textInput: Provide a text field verbatimTextOutput: Print R messages “as is”plotOutput: Display an R plot imageincludeMarkdown: Displays Markdown-formatted text files textInput example that changes text as the user types; a reactive inputtextInput("text", ...) label matches input$textverbatimTextOutput("value") label matches output$value# ui.R
shinyUI(fluidPage(
titlePanel("Hello World!"),
sidebarLayout(
sidebarPanel(textInput("text", label="Input", value="Type here...")),
mainPanel(verbatimTextOutput("value"))
)
))
# server.R
shinyServer(function(input, output) {
output$value <- renderPrint({ input$text })
})
renderPlot# ui.R
shinyUI(fluidPage(
titlePanel("Hello World!"),
sidebarLayout(
sidebarPanel(textInput("num", label="Number", value="10")),
mainPanel(plotOutput("plot"))
)
))
# server.R
shinyServer(function(input, output) {
output$plot <- renderPlot({
a <- runif(input$num)
b <- runif(input$num)
plot(a, b)
})
})
if (!require("devtools")) {
install.packages("devtools")
}
devtools::install_github("rstudio/d3heatmap")
library(shiny)
library(d3heatmap)
shinyUI(fluidPage(
titlePanel("CellMiner Heatmap"),
sidebarLayout(
sidebarPanel(
textInput("geneList", "Gene List:", "TP53 BRAF PTEN")
),
mainPanel(
d3heatmapOutput("heatmap")
)
)
))
# server.R
library(shiny)
library(rcellminer)
library(d3heatmap)
shinyServer(
function(input, output){
output$heatmap <- renderD3heatmap({
genes <- unlist(strsplit(input$geneList, " "))
expData <- getAllFeatureData(rcellminerData::molData)[["exp"]]
d3heatmap(expData[genes, 1:20], scale="column", colors="YlOrRd")
})
}
)
reactive() runs when an input changes# server.R
# Run once when the app is loaded
shinyServer(function(input, output) {
# Run once when a new user visits
output$plot <- renderPlot({
# Run every time a user makes input changes
})
})
rcharts: display of interactive plots using existing Javascript libraries
rcharts and is highly customizableDT: interactive tables using the DataTables library
htmlwidgets: allows any Javascript library to be used into Shiny appsrcytoscape.js: built with htmlwidgets is for network views
rcellminer includes examples of embedding Shiny apps in R packages